package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.ChannelSortMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ChannelBlogMapper;
import com.ruoyi.system.domain.ChannelBlog;
import com.ruoyi.system.service.IChannelBlogService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 渠道博客Service业务层处理
 * 
 * @author yanghuiliao
 * @date 2022-12-02
 */
@Service
public class ChannelBlogServiceImpl implements IChannelBlogService 
{
    @Autowired
    private ChannelBlogMapper channelBlogMapper;

    @Autowired
    private ChannelSortMapper channelSortMapper;

    /**
     * 查询渠道博客
     * 
     * @param id 渠道博客ID
     * @return 渠道博客
     */
    @Override
    public ChannelBlog selectChannelBlogById(Long id)
    {
        return channelBlogMapper.selectChannelBlogById(id);
    }

    /**
     * 查询渠道博客列表
     * 
     * @param channelBlog 渠道博客
     * @return 渠道博客
     */
    @Override
    public List<ChannelBlog> selectChannelBlogList(ChannelBlog channelBlog)
    {
        return channelBlogMapper.selectChannelBlogList(channelBlog);
    }

    /**
     * 新增渠道博客
     * 
     * @param channelBlog 渠道博客
     * @return 结果
     */
    @Override
    @Transactional
    public int insertChannelBlog(ChannelBlog channelBlog)
    {
        channelBlog.setCreateTime(DateUtils.getNowDate());
        channelBlogMapper.insertChannelBlog(channelBlog);
        return channelSortMapper.updateChannelSortRelevanceChannel(channelBlog.getParentId());
    }

    /**
     * 修改渠道博客
     * 
     * @param channelBlog 渠道博客
     * @return 结果
     */
    @Override
    public int updateChannelBlog(ChannelBlog channelBlog)
    {
        channelBlog.setUpdateTime(DateUtils.getNowDate());
        channelBlogMapper.updateChannelBlog(channelBlog);
        return channelSortMapper.updateChannelSortRelevanceChannel(channelBlog.getParentId());
    }

    /**
     * 批量删除渠道博客
     * 
     * @param ids 需要删除的渠道博客ID
     * @return 结果
     */
    @Override
    public int deleteChannelBlogByIds(Long[] ids)
    {
        return channelBlogMapper.deleteChannelBlogByIds(ids);
    }

    /**
     * 删除渠道博客信息
     * 
     * @param id 渠道博客ID
     * @return 结果
     */
    @Override
    public int deleteChannelBlogById(Long id)
    {
        return channelBlogMapper.deleteChannelBlogById(id);
    }
}
